package column

import (
	"errors"
	"fmt"
	"sanrenx.com/xyxf/app/models"
)

const (
	//修行
	Std_QianDao  = 1001
	Std_ZaoXiang = 1002
	Std_WanXiang = 1003
	Std_SongJing = 1004
	Std_ChaoJing = 1005
	Std_FanYin   = 1006
	Std_FaYuan   = 1007
	Std_ChanHui  = 1008
	Std_HuiXiang = 1009
	Std_ChanZuo  = 1010
	Std_JieYuan  = 1011

	//佛缘点
	Coin_ZhuCe   = 2001
	Coin_QianDao = 2002

	//经验
	Exp_ZhuCe   = 3001
	Exp_QianDao = 3002
)

//修行
var stdModeMaps = map[int][]interface{}{
	// 类型，字段，更新方式(每日)：inc:累加 set:赋值
	Std_QianDao:  {"签到", "qian_dao", "set"},
	Std_ZaoXiang: {"早香", "zao_xiang", "set"},
	Std_WanXiang: {"晚香", "wan_xiang", "set"},
	Std_SongJing: {"诵经", "song_jing", "inc"},
	Std_ChaoJing: {"抄经", "chao_jing", "inc"},
	Std_FanYin:   {"梵音", "fan_yuan", "inc"},
	Std_FaYuan:   {"发愿", "fa_yuan", "inc"},
	Std_ChanHui:  {"忏悔", "chan_hui", "inc"},
	Std_HuiXiang: {"回向", "hui_xiang", "inc"},
	Std_ChanZuo:  {"禅修", "chan_zuo", "inc"},
	Std_JieYuan:  {"结缘", "jie_yuan", "inc"},
}

var dailyStdMaps = map[int][]interface{}{
	//ZaoXiang: {"早晚敬香", "求好运，保平安，积功德", "去佛堂敬香", "/pages/worship/index"},
	Std_SongJing: {"虔诚诵经", "静心，安神，积功德", "诵《心经》7遍", "/pages/sutra/details/index?id=18"},
	//ChaoJing: {"手抄经书", "积德福，受庇护，消灾免祸", "手抄佛经150字", "/pages/sutra/list/index"},
	Std_ChanZuo: {"静心修禅", "抛妄想，悟本心，开智慧", "禅坐30分钟", "/pages/zazen/index"},
	//FaYuan:  {"祈福发愿", "祈求平安，长保喜乐", "为亲人祈福", "/pages/pray/index"},
	Std_ChanHui: {"忏悔消业", "静心，安神，积功德", "去忏悔己过", "/pages/pray/index?id=2022"},
	//FanYin:   {"梵音法洗", "得闻佛法，感染心灵，意念净化", "听一首梵音", "/pkg-culture/pages/sanskrit/index"},
	Std_HuiXiang: {"功德回向", "果报众生，功德无量", "修行功德回向", "/pages/pray/index?id=2023"},
	//JieYuan:  {"广结善缘", "种善根，结善缘,心有所安", "随喜结缘捐助", "/pages/alms/index"},
}

//资产
var valModeMaps = map[int][]interface{}{
	// 字段，数值，说明，关联类型

	//奖励
	Coin_ZhuCe:   {"coin", 1080, "初始注册奖励", "user"},
	Exp_ZhuCe:    {"exp", 1080, "初始注册奖励", "user"},
	Coin_QianDao: {"coin", 18, "签到奖励", "std"},
	Exp_QianDao:  {"exp", 18, "签到奖励", "std"},

	//消耗
}

/**
 * @Description: 获取每日功课maps
 * @return map[int][]interface{}
 */
func GetDailyStdMaps() map[int][]interface{} {
	return dailyStdMaps
}

/**
 * @Description: 获取字段更新模式 （累计or赋值）
 * @param key 更新字段
 * @return bool true:累计；false:赋值
 * @return error 异常信息
 */
func GetStdIncMode(key int) (string, string, error) {
	if val, ok := stdModeMaps[key]; ok {
		return val[1].(string), val[2].(string), nil
	}
	return "", "", errors.New("非规范column")
}

/**
 * @Description: 构造修行日志模型
 * @param key 字段
 * @param uid 用户ID
 * @param value 值
 * @return *models.UserStdLog 模型
 * @return error 异常信息
 */
func GetStdModel(key int, uid uint64, value interface{}) (*models.UserStdLog, error) {
	if val, ok := stdModeMaps[key]; ok {
		//生成模型
		data := models.UserStdLog{
			UserID: uid,
			Mode:   val[1].(string),
			Value:  fmt.Sprintf("%v", value),
			Remark: val[0].(string),
		}
		return &data, nil
	}
	//返回异常
	return nil, errors.New("不存在的类型")
}

/**
 * @Description: 获取字段更新模式 （累计or赋值）
 * @param key 更新字段
 * @return bool true:累计；false:赋值
 * @return error 异常信息
 */
func GetValIncMode(key int) (string, int, error) {
	if val, ok := valModeMaps[key]; ok {
		return val[0].(string), val[1].(int), nil
	}
	return "", 0, errors.New("非规范column")
}

/**
 * @Description: 构造资产数据模型
 * @param key 字段
 * @param uid 用户ID
 * @param owner 关联ID
 * @return *models.UserValLog 模型
 * @return error 异常信息
 */
func GetValModel(key int, uid uint64, owner interface{}) (*models.UserValLog, error) {
	if val, ok := valModeMaps[key]; ok {
		//生成模型
		data := models.UserValLog{
			UserID:    uid,
			Mode:      val[0].(string),
			Value:     val[1].(int),
			Remark:    val[2].(string),
			Owner:     fmt.Sprintf("%v", owner),
			OwnerType: val[3].(string),
		}
		return &data, nil
	}
	//返回异常
	return nil, errors.New("不存在的类型")
}
